// pages/mySelf/wallet/index.js
var common = require("../../../../public.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userAssets: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
        }, function () {
          that.getUserAssets()
        })
      },
      fail: function () {
        that.setData({
          userInfo: '',
          token: '',
        })
      }
    })
  },

  getUserAssets() { // 获取用户信息
    const that = this
    const tempJson = {
      userId: that.data.userInfo.id,
      token: that.data.token
    }
    common.post('/userDeposit/getUserAssets', tempJson, function (res) {
      if (res.status === 200) {
        that.setData({
          userAssets: res.data
        })
      } else {
        common.showRequestErrMsg(res)
      }
    })
  },
  toCoupons() { // 跳转优惠券中心
    wx.redirectTo({
      url: '/pages/coupons/myCoupons/index'
    })
  },
  gotoApp() {
    wx.showToast({
      title: '请使用兰陵旅游游客端app操作',
      icon: 'none'
    })
  },
})